Environment Setting
# Import required packages
library(tidyverse)
library(tmap)
library(ggplot2)
library(units)
library(sf)
library(leaflet)
library(tidycensus)
library(leafsync)
library(dbscan)
library(sfnetworks)
library(tigris)
library(tidygraph)
library(plotly)
wd <- file.path(Sys.getenv('setwd'),"work/working/School/UA_2022/external/Lab/module_2")
setwd(eval(wd))
tmap_mode('view')
What is Open Street Map
https://journal.r-project.org/archive/2013/RJ-2013-005/RJ-2013-005.pdf
https://r-spatial.org/r/2019/09/26/spatial-networks.html
https://cran.r-project.org/web/packages/dodgr/vignettes/dodgr.html
library(osmdata)
## Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
# Get bounding box coordinates for Atlanta
bb <- getbb('Atlanta, GA')
# To see where bb covers
bb_sf <- bb %>% t %>% data.frame() %>%
st_as_sf(coords = c("x", "y"), crs = 4326) %>%
st_bbox() %>%
st_as_sfc()
tm_shape(bb_sf) + tm_borders()
OSM
wiki provides a detailed description on various ‘key-value’ pairs.
To download all possible key:value pairs, you can insert
available_tags("highway") instead of manually specifying a
list of values. One caveat is that, using all available tags will
generate a large data, significantly slowing down the processing
speed.
# Get OSM road data
osm_road <- opq(bbox = bb) %>%
add_osm_feature(key = 'highway',
value = c("motorway", "trunk", "primary", "secondary", "tertiary", "unclassified",
"residential")) %>%
osmdata_sf() %>%
osm_poly2line()
names(osm_road)
## [1] "bbox" "overpass_call" "meta"
## [4] "osm_points" "osm_lines" "osm_polygons"
## [7] "osm_multilines" "osm_multipolygons"
tm_shape(osm_road$osm_lines) + tm_lines(col = "highway")